<?php

require_once "functions.php";

$msg = file_get_contents("php://input");

//file_put_contents('_tmp/_aaa', $data);
//echo $data;
//return;
// the object always gets a 'data' key
$msg = json_decode($msg, true)['payload'];

$op = $msg['op'];
$data = $msg['data'];
switch ($op) {
    
    case 'email': {
        $e = json_encode($data);
        $t = $e . "\n";
        file_put_contents('_tmp/_aaa', $t);
        echo $e;
        maxmail($data['to'], $data['from'], $data['subject'], $data['text']);
        break;
    }
    
    case 'code1': {
        $data['c'] = 'Hello';
        $e = json_encode($data);
        $t = $e . "\n";
        file_put_contents('_tmp/_aaa', $t);
        echo $e;
        break;
    }

    case 'code2' : {
        $u = array('pingo' => array("x" => 'aa', "y" => 'bb'));
        echo json_encode();
        break;
    }
    
    default : {
    }
}
die();

?>
